package util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Properties;

public class Serializador {

	private File path;

	public Serializador() throws IOException{
		InitReservasSuitesFile();
	}
	
	//INICIALIZA O PATH
	private void InitReservasSuitesFile() throws IOException {
		Properties properties = new Properties();
		try {
			File file = new File("C:\\Documents and Settings\\stefano\\workspace\\SysMotelWeb\\file.properties");
			properties.load(new FileInputStream(file));
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		path = new File(properties.getProperty("path_file_reserva"));
	}

	public void escreverObjeto(Object objeto) throws IOException {
		FileOutputStream fos = new FileOutputStream(path);
		ObjectOutputStream ous = new ObjectOutputStream(fos);
		ous.writeObject(objeto);
		ous.close();
		fos.close();
	}

	public Object lerObjeto() throws IOException, ClassNotFoundException {
		Object resp = null;
		try {
			FileInputStream fis = new FileInputStream(path);
			ObjectInputStream ois = new ObjectInputStream(fis);
			resp = ois.readObject();
			ois.close();
			fis.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		return resp;
	}

}